﻿<WindowView 
    x:Class="Poet.Views.SaveView"
    Icon="/Poet;component/App.ico"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Height="{ViewModel DefaultValue=400}" 
    Width="{ViewModel DefaultValue=700}"
    Left="{ViewModel DefaultValue=NaN}" 
    Top="{ViewModel DefaultValue=NaN}"
    WindowStartupLocation="CenterOwner"
    ResizeMode="CanResizeWithGrip"
    ShowInTaskbar="False"
    ShowActivated="True"
    Title="Poet"
    Name="This">

    <WindowView.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Poet;component/Resources/XamlStore.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <BooleanConverter OnFalse="{Localizing CheckAll}" OnTrue="{Localizing UncheckAll}" x:Key="CheckConverter"/>
        </ResourceDictionary>
    </WindowView.Resources>

    <WindowView.InputBindings>
        <KeyBinding Key="Escape" Command="ApplicationCommands.Close" CommandParameter="Cancel"/>
    </WindowView.InputBindings>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0" Margin="8" Text="{Localizing DoYouWantToSaveChangesToSelectedItems}"/>

        <Expander       
            Margin="4"
            IsExpanded="{Binding IsOpen, Mode=TwoWay, ElementName=ContextMenu}"
            HorizontalAlignment="Right" 
            VerticalAlignment="Bottom">
            <Expander.ContextMenu>
                <ContextMenu Name="ContextMenu" VerticalAlignment="Bottom">
                    <ContextMenu.Resources>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="IsCheckable" Value="True"/>
                            <Setter Property="StaysOpenOnClick" Value="True"/>
                        </Style>
                    </ContextMenu.Resources>
                    <MenuItem Header="{Localizing MulticolumnSorting}" IsChecked="{ViewModel MulticolumnSorting}"/> 
                    <Separator/>
                    <MenuItem Header="{Localizing CheckBox}" IsEnabled="False" IsChecked="True"/>
                    <MenuItem Header="{Localizing Title}" IsChecked="{Binding '[TitleColumnIsVisible]'}"/>
                    <MenuItem Header="{Localizing FileName}" IsChecked="{Binding '[FileNameColumnIsVisible]'}"/>                 
                    <MenuItem Header="{Localizing Close}" IsChecked="{Binding '[CloseColumnIsVisible]'}"/>
                    <MenuItem Header="{Localizing Encoding, Tail={Localizing BodyName, StringFormat='{} ({0})', Transformer={x:Static LocalizingManager.DefaultWithToLower}}}" IsChecked="{Binding '[EncodingBodyNameColumnIsVisible]'}"/>
                    <MenuItem Header="{Localizing Encoding, Tail={Localizing DisplayName, StringFormat='{} ({0})', Transformer={x:Static LocalizingManager.DefaultWithToLower}}}" IsChecked="{Binding '[EncodingDisplayNameColumnIsVisible]'}"/>
                    <MenuItem Header="{Localizing SaveAs}" IsChecked="{Binding '[SaveAsColumnIsVisible]'}"/>
                    <MenuItem Header="{Localizing Save}" IsChecked="{Binding '[SaveColumnIsVisible]'}"/>
                </ContextMenu>
            </Expander.ContextMenu>
        </Expander>

        <ListView 
            Grid.Row="1"     
            Margin="4 0 4 0"  
            Name="ListView" 
            ItemsSource="{Binding Items}" 
            GridViewExtensions.AutoSort="True" 
            GridViewExtensions.SaveColumnOrder="True" 
            GridViewExtensions.MulticolumnSorting="{Binding '[MulticolumnSorting,False]', Mode=TwoWay}"
            GridViewExtensions.SortDescriptionCollection="{Binding '[SortDescriptionCollection]'}">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>

            <ListView.View>

                <GridView>

                    <GridViewColumn
                        Width="{Binding '[CheckBoxColumnWidth,25]', Mode=TwoWay}" 
                        GridViewExtensions.IsVisible="True"
                        GridViewExtensions.MinWidth="25"
                        GridViewExtensions.Index="{Binding '[CheckBoxColumnIndex,0]'}">
                        <GridViewColumn.HeaderTemplate>
                            <DataTemplate>
                                <CheckBox
                                    Grid.Row="1"
                                    Margin="0"
                                    Name="TotalCheckBox"
                                    Command="ApplicationCommands.SelectAll"
                                    CommandParameter="{Binding IsChecked, ElementName=TotalCheckBox}"
                                    IsChecked="{Binding DataContext.IsAllItemsSelected, ElementName=This, Mode=OneWay}"
                                    ToolTip="{Binding IsChecked, ElementName=TotalCheckBox, Converter={StaticResource CheckConverter}}"/>
                            </DataTemplate>
                        </GridViewColumn.HeaderTemplate>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <SelectableItem 
                                    HorizontalAlignment="Center"
                                    Name="SelectableItem"       
                                    SelectedItems="{Binding DataContext.SelectedItems, ElementName=This}">
                                    <CheckBox 
                                        IsChecked="{Binding IsSelected, ElementName=SelectableItem}"
                                        Visibility="{Binding DataContext.TextEditorViewModel.IsModified, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                                </SelectableItem>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        Width="{Binding '[TitleColumnWidth,110]', Mode=TwoWay}" 
                        GridViewExtensions.PropertyName="Title"
                        GridViewExtensions.MinWidth="32"
                        GridViewExtensions.IsVisible="{Binding '[TitleColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[TiltleColumnIndex,1]'}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader>
                                <TextBlock Text="{Localizing Title}" IsHitTestVisible="False"/>
                            </GridViewColumnHeader>
                        </GridViewColumn.Header>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DataContext.Title}" ToolTip="{Binding DataContext.Title}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn
                        Width="{Binding '[FileNameColumnWidth,292]', Mode=TwoWay}"
                        GridViewExtensions.PropertyName="DataContext.FileName" 
                        GridViewExtensions.MinWidth="32"
                        GridViewExtensions.IsVisible="{Binding '[FileNameColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[FileNameColumnIndex,2]'}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader>
                                <TextBlock Text="{Localizing FileName}" IsHitTestVisible="False"/>
                            </GridViewColumnHeader>
                        </GridViewColumn.Header>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DataContext.FileName, TargetNullValue={Localizing NotSaved, StringFormat=[{0}]}}" ToolTip="{Binding DataContext.FileName}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        Width="{Binding '[CloseColumnWidth,28]', Mode=TwoWay}"                       
                        GridViewExtensions.MinWidth="28"
                        GridViewExtensions.IsVisible="{Binding '[CloseColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[CloseColumnIndex,3]'}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    Margin="0" 
                                    Padding="0" 
                                    MinWidth="12"
                                    Content="{Picture PinClose, 10}"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Center"
                                    HorizontalContentAlignment="Left"
                                    VerticalContentAlignment="Bottom"
                                    Command="ApplicationCommands.Close"  
                                    CommandParameter="DontSave"  
                                    CommandTarget="{Binding}" 
                                    ToolTip="{Localizing Close, Tail={Localizing DontSave, StringFormat='{} ({0})', Transformer={x:Static LocalizingManager.DefaultWithToLower}}}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        GridViewExtensions.PropertyName="DataContext.TextEditorViewModel.Encoding.BodyName" 
                        Width="{Binding '[EncodingBodyNameColumnWidth,64]', Mode=TwoWay}"                      
                        GridViewExtensions.MinWidth="28"
                        GridViewExtensions.IsVisible="{Binding '[EncodingBodyNameColumnIsVisible,False]'}"
                        GridViewExtensions.Index="{Binding '[EncodingBodyNameColumnIndex,4]'}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader>
                                <TextBlock Text="{Localizing Encoding}" IsHitTestVisible="False"/>
                            </GridViewColumnHeader>
                        </GridViewColumn.Header>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button  
                                    Margin="0" Padding="0" FontSize="9" MinWidth="14" 
                                    Command="ApplicationCommands.Properties" 
                                    CommandParameter=":Encoding" 
                                    Content="{Binding DataContext.TextEditorViewModel.Encoding.BodyName}" 
                                    HorizontalAlignment="Stretch" 
                                    HorizontalContentAlignment="Center" 
                                    CommandTarget="{Binding}" 
                                    ToolTip="{Binding DataContext.TextEditorViewModel.Encoding.EncodingName}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        GridViewExtensions.PropertyName="DataContext.TextEditorViewModel.Encoding.EncodingName" 
                        Width="{Binding '[EncodingDisplayNameColumnWidth,90]', Mode=TwoWay}"              
                        GridViewExtensions.MinWidth="28"
                        GridViewExtensions.IsVisible="{Binding '[EncodingDisplayNameColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[EncodingDisplayNameColumnIndex,5]'}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader>
                                <TextBlock Text="{Localizing Encoding}" IsHitTestVisible="False"/>
                            </GridViewColumnHeader>
                        </GridViewColumn.Header>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    Margin="0" Padding="0" FontSize="9" MinWidth="14"
                                    Command="ApplicationCommands.Properties" 
                                    CommandParameter=":Encoding" 
                                    Content="{Binding DataContext.TextEditorViewModel.Encoding.EncodingName}" 
                                    HorizontalAlignment="Stretch" 
                                    HorizontalContentAlignment="Center" 
                                    CommandTarget="{Binding}" 
                                    ToolTip="{Binding DataContext.TextEditorViewModel.Encoding.BodyName}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        Header="{Localizing SaveAs}"
                        Width="{Binding '[SaveAsColumnWidth,58]', Mode=TwoWay}"                       
                        GridViewExtensions.MinWidth="28"
                        GridViewExtensions.IsVisible="{Binding '[SaveAsColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[SaveAsColumnIndex,6]'}">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button
                                    Margin="0" Padding="0" FontSize="9" MinWidth="14"
                                    Content="•••"
                                    Command="ApplicationCommands.SaveAs"  
                                    CommandTarget="{Binding}" 
                                    ToolTip="{Localizing SaveAs}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn 
                        GridViewExtensions.PropertyName="DataContext.TextEditorViewModel.IsModified"
                        Width="{Binding '[SaveColumnWidth,58]', Mode=TwoWay}"         
                        GridViewExtensions.MinWidth="28"
                        GridViewExtensions.IsVisible="{Binding '[SaveColumnIsVisible,True]'}"
                        GridViewExtensions.Index="{Binding '[SaveColumnIndex,7]'}">
                        <GridViewColumn.Header>
                            <GridViewColumnHeader>
                                <TextBlock Text="{Localizing Save}" IsHitTestVisible="False"/>
                            </GridViewColumnHeader>
                        </GridViewColumn.Header>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button 
                                    Margin="0" Padding="0" FontSize="9" MinWidth="14" 
                                    Content="{Picture Save, 12}" 
                                    Command="ApplicationCommands.Save"
                                    CommandTarget="{Binding}" 
                                    ToolTip="{Localizing Save}">
                                    <Button.Resources>
                                        <Style TargetType="{x:Type Image}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ButtonBase}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
                                                    <Setter Property="Opacity" Value="0.30" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Resources>
                                </Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                </GridView>
            </ListView.View>
        </ListView>

        <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <StackPanel Margin="8" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Content="{Localizing Save}" Command="ApplicationCommands.Save" Name="SaveButton" IsDefault="True" TabIndex="0"/>
                <Button Content="{Localizing DontSave}" Command="ApplicationCommands.Close" TabIndex="1"/>
                <Button Content="{Localizing Cancel}" Command="ApplicationCommands.Close" CommandParameter="Cancel" TabIndex="2"/>
            </StackPanel>
        </ScrollViewer>
    </Grid>

</WindowView>
